package com.neulogistics.contrib.procuredcenter.infrastructure.persistence.repository;

import com.neulogistics.contrib.procuredcenter.domain.model.aggregate.Goods;
import com.neulogistics.contrib.procuredcenter.domain.repository.IGoodsRepository;
import com.neulogistics.contrib.procuredcenter.infrastructure.persistence.converter.GoodsEntityPOConverter;
import com.neulogistics.contrib.procuredcenter.infrastructure.persistence.orm.po.GoodsPO;
import com.neulogistics.contrib.procuredcenter.infrastructure.persistence.orm.service.IGoodsPOService;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class GoodsRepository implements IGoodsRepository {
    @Resource
    IGoodsPOService goodsPOService;

    @Override
    public void save(Goods goods) {
        GoodsPO goodsPO = GoodsEntityPOConverter.entityToPO(goods);
        goodsPOService.saveOrUpdate(goodsPO);
        goods.setGoodsId(goodsPO.getGoodsId());
    }

    @Override
    public Goods findById(Integer id) {
        GoodsPO goodsPO = goodsPOService.getById(id);
        Goods goods = GoodsEntityPOConverter.POToEntity(goodsPO);
        return goods;
    }

    @Override
    public void deleteById(Integer id) {
        goodsPOService.removeById(id);
    }
}
